"""
示例 1：
输入：nums1 = [1,2,2,1], nums2 = [2,2]
输出：[2,2]
示例 2:
输入：nums1 = [4,9,5], nums2 = [9,4,9,8,4]
输出：[4,9]
"""
nums1 = [4,9,5,9,9]
nums2 = [9,4,9,8,4]
nums3 = []
for i in nums1:
    if i in nums2 and i not in nums3:
        print(nums1.count(i),nums2.count(i))
        if nums1.count(i)>nums2.count(i):
            for j in range(nums2.count(i)):
                nums3.append(i)
        else:
            for j in range(nums1.count(i)):
                nums3.append(i)
print(nums3)